package com.pactera.miyuangroup.controller.web;

import com.baomidou.mybatisplus.plugins.Page;
import com.pactera.miyuangroup.db.entity.VendorPassageway;
import com.pactera.miyuangroup.filter.CurrentUser;
import com.pactera.miyuangroup.service.VendorInfoService;
import com.pactera.miyuangroup.service.VendorPassagewayService;
import com.pactera.miyuangroup.vo.request.web.VendorInfoRequest;
import com.pactera.miyuangroup.vo.response.ResultModel;
import com.pactera.miyuangroup.vo.response.ResultStatusCode;
import com.pactera.miyuangroup.vo.response.User;
import com.pactera.miyuangroup.vo.response.VoidResponse;
import com.pactera.miyuangroup.vo.response.web.VendorInfoRes;
import com.pactera.miyuangroup.vo.response.web.VendorPassagewayRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述:
 *
 * @outhor 张汉卿
 * @create 2018-04-25 10:31
 */

@Api(description = "售货机信息")
@RestController
@RequestMapping("VendorInfo")
@Slf4j
public class VendorInfoController {

    @Autowired
    private VendorInfoService vendorInfoService;
    @Autowired
    private VendorPassagewayService vendorPassagewayService;

    @ApiOperation(value = "售货机信息列表", notes = "售货机信息列表")
    @RequestMapping(value = "/getVendorInfoList", method = RequestMethod.POST)
    private ResultModel<Page<VendorInfoRes>> getVendorInfoList(@RequestBody VendorInfoRequest vendorInfoRequest, @CurrentUser User user) {


        log.info("getOrgId：{}", user.getOrgId());
        Page<VendorInfoRes> vendorInfoList = vendorInfoService.getVendorInfoList(vendorInfoRequest, user.getOrgId());

        return ResultModel.ok(vendorInfoList);
    }

    @ApiOperation(value = "查询售货机货道信息", notes = "查询售货机货道信息")
    @ApiImplicitParams({@ApiImplicitParam(value = "查询售ID", name = "vendorId", required = true, paramType = "path")})
    @RequestMapping(value = "/getPassagewayList/{vendorId}", method = RequestMethod.GET)
    private ResultModel<List<VendorPassagewayRes>> getPassagewayList(@PathVariable String vendorId) {
        log.info("售货机ID：{}", vendorId);
        List<VendorPassagewayRes> PassagewayList = vendorInfoService.getPassagewayList(vendorId);
        return ResultModel.ok(PassagewayList);
    }

    @ApiOperation(value = "同步售货机", notes = "同步售货机")
    @RequestMapping(value = "/syncVendorInfo", method = RequestMethod.GET)
    private ResultModel<VoidResponse> syncVendorInfo() {
        boolean flg = vendorInfoService.syncMiyuanVenderInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }


    @ApiOperation(value = "同步售货机货道信息", notes = "同步售货机货道信息")
    @RequestMapping(value = "/syncVendorPassagewayInfo", method = RequestMethod.GET)
    private ResultModel<VoidResponse> syncVendorPassagewayInfo() {
        boolean flg = vendorPassagewayService.syncMiyuanVendorPassagewayInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步售货机货道信息初始化", notes = "同步售货机货道信息初始化")
    @RequestMapping(value = "/initialization", method = RequestMethod.GET)
    private ResultModel<VoidResponse> Initialization() {
        vendorPassagewayService.excelImport();
        return ResultModel.ok();
    }

}
